package com.shangpintechnology.sci.jni;//package declare not in dll

public class NativeCall {

	static {   
	     System.loadLibrary("JniCall");   
	 } 
 public native boolean initCOM();
 public native boolean openCOM();
 public native boolean readEPC();
 public native byte[] revEPC();
public native boolean writeEPC(byte[] psw,byte[] epc);
 public native boolean writeData(byte[]psw,byte[] data);
 public native byte[] readData();
 public static void main(String[]args){
	 NativeCall nc = new NativeCall();
	 boolean iInit = nc.initCOM();
	 System.out.println(iInit);
	 boolean roOpen = nc.openCOM();
	 System.out.println(roOpen+"");
	 boolean roRead =nc.readEPC();
	 System.out.println(roRead+"");
	 ///////
	 byte[] b = {1,1,1,1,1,1,1,1,11,1};
	 boolean bwepc = nc.writeEPC(b,b);
	 byte[]rdata= nc.readData();
	 boolean brdata = nc.writeData(new byte[]{0,0,0,0,0,0,0,0}, b);
	 System.out.println(bwepc+""+rdata+""+brdata);
	 ///////////
	 for(int i =0;i<10;i++){
	 readprint(nc);
	   roRead =nc.readEPC();
	 System.out.println(roRead+"");
	 try{
	 Thread.sleep(1000);
	}catch(Exception e){
	 System.out.println(e+"E..");
	}
	 } readprint(nc);
	
	}
	
public static void readprint(NativeCall nc){
byte[] roRev = nc.revEPC();
	 if(roRev==null){
	 System.out.println("roRev =null");
	 }else{
		 System.out.print("EPC:[");
		printHexString(roRev);
		
		 System.out.println("]");
		 
	 }
 
}
public static void printHexString( byte[] b) { 
for (int i = 0; i < b.length; i++) { 
String hex = Integer.toHexString(b[i] & 0xFF); 
if (hex.length() == 1) { 
hex = '0' + hex; 
} 
System.out.print(hex.toUpperCase() ); 
} 

}
public static String getHexString( byte[] b) { 
	for (int i = 0; i < b.length; i++) { 
	String hex = Integer.toHexString(b[i] & 0xFF); 
	if (hex.length() == 1) { 
	hex = '0' + hex; 
	} 
	return hex.toUpperCase(); 
	} 
	return null;
	}
private static NativeCall nativeCall;
public static NativeCall singleton() {
	if(nativeCall==null){
		nativeCall = new NativeCall();
		nativeCall.initCOM();
		nativeCall.openCOM();
	}
	return nativeCall;
}

}
